define(["jquery", "bootstrap", "backend", "table", "form"], function (
    $,
    undefined,
    Backend,
    Table,
    Form
) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: "company/index",
                    add_url: "company/add",
                    edit_url: "company/edit",
                    del_url: "company/del",
                    multi_url: "company/multi",
                    recharge_url: "company/recharge",
                    table: "company"
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: "id",
                sortName: "id",
                columns: [
                    [
                        {checkbox: true},
                        {field: "id", title: __('Id'), sortable: true},
                        {field: "title", title: __("Title")},
                        {field: "admin.username", title: __("Admin.username")},
                        {field: "name", title: __("Name")},

                        {field: "province.name", title: __("Province")},
                        {field: "city.name", title: __("City")},
                        {field: "country.name", title: __("Country")},
                        {field: "address", title: __("Address")},
                        {field: "balance", title: __("Balance")},
                        {field: "tel", title: __("Tel")},
                        {field: "technology", title: __("Technology")},
                        {field: "admin.nickname", title: __("Admin_id")},
                        {
                            field: "admin.logintime",
                            title: __("Admin.logintime"),
                            operate: "RANGE",
                            addclass: "datetimerange",
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: "operate",
                            title: __("Operate"),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'recharge',
                                    text: '充值',
                                    title: __('充值'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    refresh: true,
                                    url: $.fn.bootstrapTable.defaults.extend.recharge_url
                                }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        recharge: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
